/*
 * @Author: 清香白莲 1243327527@qq.com
 * @Date: 2023-08-16 17:44:08
 * @LastEditors: 清香白莲 1243327527@qq.com
 * @LastEditTime: 2023-09-21 11:59:30
 * @FilePath: /shang_study/src/store/shoppingcart.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {reqCategoryList, reqGetCartList} from '@/api'

export default {
    namespaced: true,
    actions: {
        // demo2(content, value) {
        //     console.log('demo2调用了')
        //     console.log('demo2处理了一些事情')
        //     content.dispatch('add', value)
        // },
        async categoryList(content, value) {
            let result = await reqCategoryList()
            if (result.code == 200) {
                content.commit('CATEGORYLIST', result.data)
            }else {
                content.commit('CATEGORYLIST', [])
            }
        },
        async getCartList(content, value) {
            let result = await reqGetCartList();
            console.log(result);
            if (result.code == 200) {
                content.commit('GETCARTLIST', result.data);
            }else {
                content.commit('GETCARTLIST', []);
            }
        }
    },
    mutations: {
        CATEGORYLIST(state, categoryList) {
            state.categoryList = categoryList;
        },
        GETCARTLIST(state, cartList) {
            state.cartList = cartList;
        },

    },
    state: {
        categoryList: [],
        cartList: [],
    },
    getters: {
        cartInfoList(state) {
            return state.cartList[0].cartInfoList || [];
        }
    }
}